POV-Ray : Newsgroups : povray.general : Suggestion for new object : Re: Suggestion for new object Server Time
13 Aug 2024 19:23:48 EDT (-0400)
  Re: Suggestion for new object  
From: Chris Colefax
Date: 11 Jul 1998 11:27:00
Message: <35A758E2.B905443A@geocities.com>
Mikael Gustafsson wrote:
> 
> Sorry for a second post but the last sentence was a bit confusing.
> 
> With POV-Ray 3.1 I think it would be possible to incorporate a new object.
> Well, here's my two cents on the subject. The current box is probably one of
> the most used objects in POV, but it has some drawbacks. The current syntax
> only allows boxes with 90 degree corners. But if POV inwoked a new object
> that lets the user define all eight corners of the box, it would among other
> things help creating #while loops that have flat areas as complex matrix
> transformations that are required with the current boxes coule be avoided.

Perhaps the file below will do what you want; the syntax (after
including the file) is as follows:

   metabox (<Point1>, <Point2>, <Point3>, <Point4>, <Point5>, <Point6>, <Point7>,
<Point8>)

which creates a solid box with the vertices as specified.  Points 1 to
4 should specify one face of the metabox (in either clockwise or anti-
clockwise direction), with points 5 to 8 specifying the opposide side
of the box (specified in the same direction as the first face).

As has been mentioned in other messages, though, it is possible that
the points will specify a box with one or more faces not being flat.  In
this case, the macro will automatically create a metabox with bent faces
to fit all eight vertices.  Alternatively, you can create such metaboxes
directly using the flat_metabox macro:

   flat_metabox (<Point1>, <Point2>, <Point3>, <Point4>, <Point5>, <Point6>, <Point7>,
<Point8>)
   
or, you can create the boxes with smooth faces (that curve to fit the
vertices) using the smooth_metabox macro:

   smooth_metabox (<Point1>, <Point2>, <Point3>, <Point4>, <Point5>, <Point6>,
<Point7>, <Point8>)

Note that, unlike the solid metabox, the flat_metabox and
smooth_metabox cannot be used in CSG operations (although they can be
clipped).  However, they can be used as media containers, eg:

   object {smooth_metabox (
      <-1, -2, -1>, <1, -1, -1>, <1, -2, 1>, <-1, -1, 1>,
      <0, 2, -1>, <1, 1, 0>, <0, 2, 1>, <-1, 1, 0>)
      hollow
      pigment {rgbf 1}
      interior {media {.....}}
      }


// -- Metabox.inc ----------------------------

#macro flat_metabox (FP1, FP2, FP3, FP4, BP1, BP2, BP3, BP4)
   mesh {
      triangle {FP1, FP2, FP3} triangle {FP1, FP3, FP4}  // Front
      triangle {FP1, BP1, BP2} triangle {FP1, BP2, FP2}  // Top
      triangle {FP1, FP4, BP4} triangle {FP1, BP4, BP1}  // Left
      triangle {BP1, BP4, BP3} triangle {BP1, BP3, BP2}  // Back
      triangle {FP4, FP3, BP3} triangle {FP4, BP3, BP4}  // Bottom
      triangle {FP2, BP2, BP3} triangle {FP2, BP3, FP3}  // Right
      }
#end

#macro metabox (FP1, FP2, FP3, FP4, BP1, BP2, BP3, BP4)
   #local _MB_normal1 = -vcross(FP1 - FP2, FP2 - FP3);
   #if (vdot(_MB_normal1, FP4 - FP1) != 0) #local _MB_warning = "point1, point2,
point3, and point4 are not co-planar" #end

   #local _MB_normal2 = -vcross(FP1 - BP1, BP1 - BP2);
   #if (vdot(_MB_normal2, FP2 - FP1) != 0) #local _MB_warning = "point1, point2,
point5, and point6 are not co-planar" #end

   #local _MB_normal3 = -vcross(FP1 - FP4, FP4 - BP4);
   #if (vdot(_MB_normal3, BP1 - FP1) != 0) #local _MB_warning = "point1, point4,
point5, and point8 are not co-planar" #end

   #local _MB_normal4 = -vcross(BP1 - BP4, BP4 - BP3);
   #if (vdot(_MB_normal4, BP2 - BP1) != 0) #local _MB_warning = "point5, point6,
point7, and point8 are not co-planar" #end

   #local _MB_normal5 = -vcross(FP4 - FP3, FP3 - BP3);
   #if (vdot(_MB_normal5, BP4 - FP4) != 0) #local _MB_warning = "point3, point4,
point7, and point8 are not co-planar" #end

   #local _MB_normal6 = -vcross(FP2 - BP2, BP2 - BP3);
   #if (vdot(_MB_normal6, FP3 - FP2) != 0) #local _MB_warning = "point2, point3,
point6, and point7 are not co-planar" #end
   
   #ifdef (_MB_warning)
      #warning concat("metabox: ", _MB_warning, ", flat_metabox created.\r\n")
      flat_metabox (FP1, FP2, FP3, FP4, BP1, BP2, BP3, BP4)

   #else
      #local _MB_axis = ((BP1 + BP2 + BP3 + BP4) / 4) - ((FP1 + FP2 + FP3 + FP4) / 4);
      #if (vlength(_MB_normal1 - _MB_axis) < vlength(-_MB_normal1 - _MB_axis))
         #local _MB_normaldir = -1;
      #else
         #local _MB_normaldir = 1;
      #end

      intersection {
         plane {_MB_normaldir * _MB_normal1, 0 translate FP1}
         plane {_MB_normaldir * _MB_normal2, 0 translate FP1}
         plane {_MB_normaldir * _MB_normal3, 0 translate FP1}
         plane {_MB_normaldir * _MB_normal4, 0 translate BP1}
         plane {_MB_normaldir * _MB_normal5, 0 translate FP4}
         plane {_MB_normaldir * _MB_normal6, 0 translate FP2}
      }
   #end
#end

#macro smooth_metabox (FP1, FP2, FP3, FP4, BP1, BP2, BP3, BP4)
   union {
      #local _MB_face = 0; #while (_MB_face < 6)
         #switch (_MB_face)
            #case (0) #local P1 = FP1 * <1, 1, 1>; #local P2 = FP2 * <1, 1, 1>;
               #local P3 = FP3 * <1, 1, 1>; #local P4 = FP4 * <1, 1, 1>; #break
            #case (1) #local P1 = FP1 * <1, 1, 1>; #local P2 = BP1 * <1, 1, 1>;
               #local P3 = BP2 * <1, 1, 1>; #local P4 = FP2 * <1, 1, 1>; #break
            #case (2) #local P1 = FP1 * <1, 1, 1>; #local P2 = FP4 * <1, 1, 1>;
               #local P3 = BP4 * <1, 1, 1>; #local P4 = BP1 * <1, 1, 1>; #break
            #case (3) #local P1 = BP1 * <1, 1, 1>; #local P2 = BP4 * <1, 1, 1>;
               #local P3 = BP3 * <1, 1, 1>; #local P4 = BP2 * <1, 1, 1>; #break
            #case (4) #local P1 = FP4 * <1, 1, 1>; #local P2 = FP3 * <1, 1, 1>;
               #local P3 = BP3 * <1, 1, 1>; #local P4 = BP4 * <1, 1, 1>; #break
            #case (5) #local P1 = FP2 * <1, 1, 1>; #local P2 = BP2 * <1, 1, 1>;
               #local P3 = BP3 * <1, 1, 1>; #local P4 = FP3 * <1, 1, 1>;
         #end

         #local PA = (P2 - P1) / 3;
         #local PB = (P4 - P1) / 3;
         #local PC = (P3 - P2) / 3;
         #local PD = (P3 - P4) / 3;
         #local PE = (P1 + PB); #local PF = P2 + PC; #local PG = (PF - PE) / 3;
         #local PH = P4 - PB; #local PI = P3 - PC; #local PJ = (PI - PH) / 3;

      bicubic_patch {type 1 u_steps 2 v_steps 2 flatness .01
         P1,  P1+PA,  P2-PA,  P2,
         PE,  PE+PG,  PF-PG,  PF,
         PH,  PH+PJ,  PI-PJ,  PI,
         P4,  P4+PD,  P3-PD,  P3}

      #local _MB_face = _MB_face + 1; #end
      }
#end

// -- End File --------------------------------


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.